let EventEmiter = require("events")
let myevent = new EventEmiter();

//1.绑定自定义事件
//on 类似 addEventListener

let fn1 =function(){
    console.log("event1111")
}

let fn2 =function(){
    console.log("event222")
}

//直接绑定

// myevent.on('e1',fn1)
// myevent.on('e2',fn2)

//绑定事件，只执行一次
myevent.once('e1',fn1);
myevent.once('e2',fn2);

//移除事件
//一，off
// myevent.off('e1',fn1)
//二
// myevent.removeListener("e2",fn2)
//三
myevent.removeAllListeners("e1")


//2触发自定义事件
setTimeout(()=>{
    // myevent.emit('e1');
    // myevent.emit('e2');
    myevent.emit('e1');
    myevent.emit('e2');
},1000)